﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

public partial class _Default : webapp4U.UI.BasePage
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    void ShowMessageBox(string text)
    {
        MessageBox.Text = text;
        MessageBox.ShowOnPageLoad = true;
    }
   
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        ClickLogin();
    }
    void ClickLogin()
    {
        dt = new ClassExecute.ClassExecute();
        string kq = "notauthentication";
        try
        {
            kq = dt.GetDataDepend(str, "k_checkLogin", CommandType.StoredProcedure, ref error,
               new SqlParameter("@UserName", txtUser.Text),
               new SqlParameter("@Password", dt.GetMd5Sum(txtPass.Text)));

            if ((kq != "notauthentication") && (kq != ""))
            {
                Session["user"] = txtUser.Text;
                Session["UserType"] = kq;
                Session["sitecode"] = dt.GetDataDepend(str, "k_getSiteCodeByUser", CommandType.StoredProcedure, ref error,
                    new SqlParameter("@UserName", txtUser.Text));
                Session["Adncode"] = dt.GetDataDepend(str, "[k_getAdncode]", CommandType.StoredProcedure, ref error,
                    new SqlParameter("@Username", txtUser.Text));
                Response.Redirect(webapp4U.Globals.ApplicationPath + "Pages/Management/Default.aspx", true);
            }
            else
            {
                ShowMessageBox("Tài khoản đăng nhập không hợp lệ");
            }
        }
        catch 
        {
            return;
        }
    }
}